import threading
import time


def worker(num, sleep_time):
    print(f"Thread {num} starting")
    time.sleep(sleep_time)  # 模拟工作进行
    print(f"Thread {num} finished")


def main():
    threads = []
    for i in range(3):
        t = threading.Thread(target=worker, args=(i, i))
        t.start()
        threads.append(t)

    for t in threads:
        t.join()  # 确保所有线程完成后再继续

    print("All threads finished")


if __name__ == "__main__":
    main()